package com.angel.controller;

import com.angel.bean.UserInfo;
import com.angel.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 找回密码
 */
@Controller
@RequestMapping("/f")
public class UserFindPwd {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 返回找回密码页面
     * @return
     */
    @RequestMapping("/findpwd")
    public String findPwd(){
        System.out.println("找回密码");
        return "user_find_pwd";
    }

    /**
     * 修改密码
     * @param userInfo
     * @return
     */
    @RequestMapping("/modifyPwd")
    @ResponseBody
    public Object modifyPwd(UserInfo userInfo){
        Map<String,Object> map=new HashMap<>();
        //System.out.println("-----"+userInfo.getUserTel());
        UserInfo userInfo1=new UserInfo();
        userInfo1.setUserTel(userInfo.getUserTel());
        UserInfo result=userInfoService.findOne(userInfo1);
        if (result!=null){
            //System.out.println("------更新---");
            userInfo.setId(result.getId());
            int i= userInfoService.update(userInfo);
            if (i!=0){
                map.put("emp",true);
            }else {
                map.put("emp","none");
            }
        }else {
            map.put("emp",false);
        }
        return map;
    }
}
